package com.zzyl.nursing.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zzyl.nursing.vo.MemberFamilyDeviceVo;
import org.apache.ibatis.annotations.Mapper;
import java.util.List;
import com.zzyl.nursing.domain.FamilyMemberElder;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

/**
 * 客户老人与家属关联Mapper接口
 * 
 * @author laoYe
 * @date 2025-11-03
 */
@Mapper
public interface FamilyMemberElderMapper extends BaseMapper<FamilyMemberElder> {
    /**
     * 查询客户老人与家属关联
     * 
     * @param id 客户老人与家属关联主键
     * @return 客户老人与家属关联
     */
    FamilyMemberElder selectFamilyMemberElderById(Long id);

    /**
     * 查询客户老人与家属关联列表
     * 
     * @param familyMemberElder 客户老人与家属关联
     * @return 客户老人与家属关联集合
     */
    List<FamilyMemberElder> selectFamilyMemberElderList(FamilyMemberElder familyMemberElder);

    /**
     * 新增客户老人与家属关联
     * 
     * @param familyMemberElder 客户老人与家属关联
     * @return 结果
     */
    int insertFamilyMemberElder(FamilyMemberElder familyMemberElder);

    /**
     * 修改客户老人与家属关联
     * 
     * @param familyMemberElder 客户老人与家属关联
     * @return 结果
     */
    int updateFamilyMemberElder(FamilyMemberElder familyMemberElder);

    /**
     * 删除客户老人与家属关联
     * 
     * @param id 客户老人与家属关联主键
     * @return 结果
     */
    int deleteFamilyMemberElderById(Long id);

    /**
     * 批量删除客户老人与家属关联
     * 
     * @param ids 需要删除的数据主键集合
     * @return 结果
     */
    int deleteFamilyMemberElderByIds(Long[] ids);

    /**
     * 查询用户下的所有家属
     * @param userId
     * @return
     */
    @Select("SELECT fme.id, fme.elder_id, fme.family_member_id, e.name AS elderName " +
            "FROM family_member_elder fme " +
            "LEFT JOIN elder e ON fme.elder_id = e.id " +
            "WHERE fme.family_member_id = #{userId}")
    List<MemberFamilyDeviceVo> selectFamilyWithElder(Long userId);

    /**
     * 查看已绑定家人列表（分页查询）
     * @param userId
     * @return
     */

    IPage<MemberFamilyDeviceVo> selectFamilyWithElderByPage( IPage<MemberFamilyDeviceVo> page,
                                                             @Param("userId") Long userId);
}
